package com.nmsl.sn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.sn.domain.SnPrescriptionInfo;
import com.nmsl.sn.service.ISnPrescriptionInfoService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 患者处方信息Controller
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@RestController
@RequestMapping("/sn/prescriptionInfo")
public class SnPrescriptionInfoController extends BaseController
{
    @Autowired
    private ISnPrescriptionInfoService snPrescriptionInfoService;

    /**
     * 查询患者处方信息列表
     */
    @PreAuthorize("@ss.hasPermi('sn:prescriptionInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnPrescriptionInfo snPrescriptionInfo)
    {
        startPage();
        List<SnPrescriptionInfo> list = snPrescriptionInfoService.selectSnPrescriptionInfoList(snPrescriptionInfo);
        return getDataTable(list);
    }

    /**
     * 导出患者处方信息列表
     */
    @PreAuthorize("@ss.hasPermi('sn:prescriptionInfo:export')")
    @Log(title = "患者处方信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnPrescriptionInfo snPrescriptionInfo)
    {
        List<SnPrescriptionInfo> list = snPrescriptionInfoService.selectSnPrescriptionInfoList(snPrescriptionInfo);
        ExcelUtil<SnPrescriptionInfo> util = new ExcelUtil<SnPrescriptionInfo>(SnPrescriptionInfo.class);
        util.exportExcel(response, list, "患者处方信息数据");
    }

    /**
     * 获取患者处方信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:prescriptionInfo:query')")
    @GetMapping(value = "/{prescriptionInfoId}")
    public AjaxResult getInfo(@PathVariable("prescriptionInfoId") Long prescriptionInfoId)
    {
        return success(snPrescriptionInfoService.selectSnPrescriptionInfoByPrescriptionInfoId(prescriptionInfoId));
    }

    /**
     * 新增患者处方信息
     */
    @PreAuthorize("@ss.hasPermi('sn:prescriptionInfo:add')")
    @Log(title = "患者处方信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnPrescriptionInfo snPrescriptionInfo)
    {
        return toAjax(snPrescriptionInfoService.insertSnPrescriptionInfo(snPrescriptionInfo));
    }

    /**
     * 修改患者处方信息
     */
    @PreAuthorize("@ss.hasPermi('sn:prescriptionInfo:edit')")
    @Log(title = "患者处方信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnPrescriptionInfo snPrescriptionInfo)
    {
        return toAjax(snPrescriptionInfoService.updateSnPrescriptionInfo(snPrescriptionInfo));
    }

    /**
     * 删除患者处方信息
     */
    @PreAuthorize("@ss.hasPermi('sn:prescriptionInfo:remove')")
    @Log(title = "患者处方信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prescriptionInfoIds}")
    public AjaxResult remove(@PathVariable Long[] prescriptionInfoIds)
    {
        return toAjax(snPrescriptionInfoService.deleteSnPrescriptionInfoByPrescriptionInfoIds(prescriptionInfoIds));
    }
}
